//ssock_tcpsock.h
/*
 * Copyright 2010 Samuel C. Payson. All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *	
 * THIS SOFTWARE IS PROVIDED BY SAMUEL C. PAYSON ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SAMUEL C. PAYSON OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *	
 * The views and conclusions contained in the software and documentation are those of the
 * authors and should not be interpreted as representing official policies, either expressed
 * or implied, of Samuel C. Payson.
*/
#ifndef _SCP_SSOCK_TCP_H_
#define _SCP_SSOCK_TCP_H_

#include <ssock/ssock_system.h>

/* not used
#ifndef SOCK_RECV_BUFFER_SIZE
//512kB
#define SSOCK_RECV_BUFFER_SIZE 524288
#endif
*/

#ifndef SSOCK_LISTEN_BACKLOG
#define SSOCK_LISTEN_BACKLOG SOMAXCONN
#endif

typedef struct
{
	struct addrinfo tcp_ai;
	SOCKET tcp_fd;
	unsigned short tcp_port;
}ssock_tcpsocket;


ssock_tcpsocket * ssock_newtcp(const char * node, const char * port);

inline int ssock_tcpconnect(ssock_tcpsocket * sock);

inline void ssock_tcpclose(ssock_tcpsocket * sock);

inline void ssock_freetcp(ssock_tcpsocket * sock);

int ssock_tcpsend(ssock_tcpsocket * sock, void * data, size_t sz);

/*void ssock_enable_volatile_recv(size_t buff_size);

ssock_packet * ssock_tcprecv_alloc(ssock_tcpsocket * sock);

ssock_packet * ssock_tcprecv_volatile(ssock_tcpsocket * sock);*/

int ssock_tcprecv(ssock_tcpsocket * sock, void * buff, size_t sz);

inline int ssock_tcprecv_next(ssock_tcpsocket * sock, void * buff, size_t sz);

int ssock_tcplisten(ssock_tcpsocket * sock);

ssock_tcpsocket * ssock_tcpaccept(ssock_tcpsocket * listener);

#endif